package com.example.demoddd.application.in.rest.controller;


import com.example.demoddd.domain.userauth.model.entity.StPermissions;
import com.example.demoddd.domain.userauth.services.PermissionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/permission")
@RequiredArgsConstructor
public class PermissionController {
    private final PermissionService permissionService;

    //@Tag() 用于说明或定义的标签
    @Tag(name = "刷新系统权限到权限表")
    //@Schema 用于描述实体
    @PreAuthorize("hasAuthority('/permission/refreshPreAuthorizeToPermission')")
    @PostMapping("/refreshPreAuthorizeToPermission")
    public ResponseEntity<String> refreshPreAuthorizeToPermission() {
        permissionService.refreshPreAuthorizeToPermission();
        return ResponseEntity.ok("处理成功");
    }


    @Tag(name = "查看全部权限")
    //@Schema 用于描述实体
    @PreAuthorize("hasAuthority('/permission/queryall')")
    @PostMapping("/queryall")
    public ResponseEntity<List<StPermissions>> queryall() {
        List<StPermissions> queryall = permissionService.queryall();
        return ResponseEntity.ok(queryall);
    }


}

